﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.IO;

namespace HRDexCapstoneProject.Functions.JobPosting
{
    public partial class ApplicationForm : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void txtSubmit_Click(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection("Data Source=(local); Initial Catalog=HRdexDB; Integrated Security=SSPI");
            SqlDataAdapter adapter = new SqlDataAdapter();
            DataSet ds = new DataSet();

            conn.Open();

            SqlCommand cmd = new SqlCommand("Insert Into formApplicant (fName, lName, Address, contactNum, email, birthday, JobID, Resume, pubDate) Values (@fName, @lName, @Address, @contactNum, @email,@birthday, @JobID, @Resume, @pubDate)", conn);
            Stream fs = fuAttachment.PostedFile.InputStream;
            BinaryReader br = new BinaryReader(fs);
            Byte[] bytes = br.ReadBytes((Int32)fs.Length);

            cmd.Parameters.Add("@fNAme", SqlDbType.VarChar).Value = txtFName.Text;
            cmd.Parameters.Add("@lNAme", SqlDbType.VarChar).Value = txtLName.Text;
            cmd.Parameters.Add("@address", SqlDbType.VarChar).Value = txtAddress.Text;
            cmd.Parameters.Add("@contactNum", SqlDbType.VarChar).Value = txtContactNo.Text;
            cmd.Parameters.Add("@email", SqlDbType.VarChar).Value = txtEmail.Text;
            cmd.Parameters.Add("@birthday", SqlDbType.VarChar).Value = ddl0Month.Text + "/" + ddl0Day.Text + "/" + ddl0Year.Text;
            cmd.Parameters.Add("@jobID", SqlDbType.Int).Value = ddlJob.Text;
            cmd.Parameters.Add("@resume", SqlDbType.Binary).Value = bytes;
            cmd.Parameters.Add("@pubDate", SqlDbType.DateTime).Value = DateTime.Now;

            cmd.ExecuteNonQuery();
            
            conn.Close();
        }
    }
}